package ma.cdm.rapports.datasources;

import java.util.List;

import ma.cdm.compteRenduVO.PersonneVO;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;

public class PersonneDataSource implements JRDataSource {
    private List<PersonneVO> personnes;
    private int index = -1;
    public PersonneDataSource(List<PersonneVO> personnes) {
        super();
        this.personnes = personnes;
    }
    public Object getFieldValue(JRField field) throws JRException {
        String fieldName = field.getName();
        PersonneVO pers = personnes.get(index);
        if ("nom".equals(fieldName)) {
            return pers.getCivilite()+" "+pers.getNom() +" "+pers.getPrenom();
        } else if ("departement".equals(fieldName)) {
            return pers.getDepartement();
        } 
        return "";
    }
    public boolean next() throws JRException {
        return ++index < personnes.size();
    }
}